﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Demo.Framework.Strings.DuplicateChar
{
    struct Stream :IStream
    {
        private List<char> _stream;
        private int _cursor;

        public Stream(List<char> inputStream)
        {
            if (inputStream == null)
            {
                throw new Exception("Input stream cannot be null and must have atleast one entry");
            }
            _stream = inputStream;
            _cursor = -1;
        }
        
        public bool HasNext()
        {
            return (_cursor + 1 <= _stream.Count - 1);
        }

        public char GetNext()
        {
            if (HasNext())
            {
                _cursor++;
                return _stream[_cursor];
            }
            else
            {
                throw new Exception("Attemp to access element beyond the length of the stream");
            }
        }
    }
}
